package com.hup.utils.io.socket.netty.view;

import com.hup.utils.swing.customView.ImageLabel;
import lombok.Getter;
import lombok.Setter;

import javax.swing.*;
import java.awt.image.BufferedImage;

/**
 * 显示录屏图像的窗口
 *
 * @author hugan
 * @date 2021/5/5
 */
public class ScreenFrame extends JFrame {
    @Setter
    @Getter
    private String baseTitle;

    private final ImageLabel imageLabel;

    public ScreenFrame() {
        super("投屏");
        setBaseTitle(getTitle());

        imageLabel = new ImageLabel();
        add(imageLabel);
        setSize(600, 1000);
        setLocationRelativeTo(null);

        setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    }

    public void setImage(BufferedImage image) {
        imageLabel.setBackgroundImage(image);
    }

    public void setSubTitle(String text) {
        if (text != null) {
            setTitle(getBaseTitle() + " - " + text);
        } else {
            setTitle(getBaseTitle());
        }
    }
}
